package com.power.sifa.approve.model;


import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.plf.core.base.model.Ha_attachment;
import com.plf.core.common.annotations.FieldEnumText;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.approve.model.enumeration.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 审批过程材料实体类
 */

@Entity
@ApiModel(value = "审批过程材料")
@Data
@Table(name = "Aprv_process_materials", schema = "sfapprove")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
//@IdClass(Aprv_process_materials.Aprv_process_materialsPK.class) 用于复合组件
public class Aprv_process_materials extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "applyid+nanoid")
    private String id;

    @ApiModelProperty(value = "附件id")
    private String attachid;

    /**
     * {@link Tp_proctype}
     */
    @ApiModelProperty(value = "类型")
    private Integer type;

    @ApiModelProperty(value = "创建人id")
    private String createuserid;

    @ApiModelProperty(value = "创建人")
    private String createuser;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createtime;

    @ApiModelProperty(value = "引用主表id")
    private String applyid;

    /**
     * {@link Tp_procmaterialEnum}
     */
    @ApiModelProperty(value = "材料类型")
    private Integer mattype;

    @ApiModelProperty(value = "所属阶段")
    private Integer stage;

    @ApiModelProperty(value = "所属分类")
    private Integer classify;

    @ApiModelProperty(value = "自定义材料依赖id")
    private String reply_attachid;

    @ApiModelProperty(value = "是否盖章")
    private Integer sign = Tp_sign.UNSIGN;

    @ApiModelProperty(value = "子流程applyid")
    private String sonapplyid;

    /**
     * 类型文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_procdocument", valuefield = "type")
    private String type_text;

    /**
     * 附件列表
     */
    @Transient
    private Ha_attachment file;

    /**
     * 自定义材料类型
     */
    @Transient
    private Aprv_materials_customer customerMaterial;

    /**
     * 被申请人
     */
    @Transient
    private String targetname;

    /**
     * 案号
     */
    @Transient
    private String acceptcode;


    /**
     * 是否盖章文本
     */
    @Transient
    @FieldEnumText(eum = "Tp_sign", valuefield = "sign")
    private String sign_text;

    public Map<String, Object> parseMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", this.getId());
        map.put("attachid", this.getAttachid());
        map.put("type_text", this.type_text);
        map.put("type", this.getType());
        map.put("createuserid", this.getCreateuserid());
        map.put("createuser", this.getCreateuser());
        map.put("createtime", this.getCreatetime());
        map.put("applyid", this.getApplyid());
        return map;
    }

    public String getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (String) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Aprv_process_materialsPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (String) key;

        //Aprv_process_materialsPK pk = (Aprv_process_materialsPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

    /**
     * 构造方法
     * @param tp_classifyEnum
     */
    public Aprv_process_materials(Tp_classifyEnum tp_classifyEnum) {
        this();
        this.setClassify(tp_classifyEnum.getId());
    }

    /**
     * 构造方法
     * @param tp_stageEnum
     */
    public Aprv_process_materials(Tp_stageEnum tp_stageEnum) {
        this();
        this.setStage(tp_stageEnum.getId());
    }

    /**
     * 构造方法
     * @param tp_classifyEnum
     * @param tp_stageEnum
     */
    public Aprv_process_materials(Tp_classifyEnum tp_classifyEnum, Tp_stageEnum tp_stageEnum) {
        this();
        this.setClassify(tp_classifyEnum.getId());
        this.setStage(tp_stageEnum.getId());
    }


    /**
     * 构造方法
     * @param procmaterialEnum
     */
    public Aprv_process_materials(Tp_procmaterialEnum procmaterialEnum) {
        this();
        if (ObjectUtil.isNotEmpty(procmaterialEnum)) {
            if (ObjectUtil.isNotNull(procmaterialEnum.getClassifyEnum())) {
                this.setClassify(procmaterialEnum.getClassifyEnum().getId());
            }
            if (ObjectUtil.isNotNull(procmaterialEnum.getStageEnum())) {
                this.setStage(procmaterialEnum.getStageEnum().getId());
            }
        }
    }

}
